package org.qqcui.designpattern.patterns.state;

/**
 * 抽奖业务类
 *
 * @author cuiqingqiang
 * @version 1.0
 * @date 2022/5/7 14:14
 **/
public class RaffleActivity {

    /**
     * 记录当前状态
     */
    private State state;

    /**
     * 奖品数量
     */
    private int count = 0;

    /**
     * 不可抽奖状态
     */
    private NoRaffleState noRaffleState = new NoRaffleState(this);

    /**
     * 可抽奖状态
     */
    private CanRaffleState canRaffleState = new CanRaffleState(this);

    /**
     * 发送奖品状态
     */
    private DispenseState dispenseState = new DispenseState(this);

    /**
     * 奖品抽完状态
     */
    private DispenseOutState dispenseOutState = new DispenseOutState(this);

    public RaffleActivity(int count) {
        // 初始化状态为未抽奖状态
        state = noRaffleState;
        this.count = count;
    }

    /**
     * 扣除积分
     */
    public void deduceScore() {
        state.deduceScore();
    }

    public void raffle() {
        if (state.raffle()) {
            // 发奖
            state.dispensePrize();
        }
    }

    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    public int getCount() {
        int current = count;
        count--;
        return current;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public NoRaffleState getNoRaffleState() {
        return noRaffleState;
    }

    public void setNoRaffleState(NoRaffleState noRaffleState) {
        this.noRaffleState = noRaffleState;
    }

    public CanRaffleState getCanRaffleState() {
        return canRaffleState;
    }

    public void setCanRaffleState(CanRaffleState canRaffleState) {
        this.canRaffleState = canRaffleState;
    }

    public DispenseState getDispenseState() {
        return dispenseState;
    }

    public void setDispenseState(DispenseState dispenseState) {
        this.dispenseState = dispenseState;
    }

    public DispenseOutState getDispenseOutState() {
        return dispenseOutState;
    }

    public void setDispenseOutState(DispenseOutState dispenseOutState) {
        this.dispenseOutState = dispenseOutState;
    }
}
